<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Response Data Formats | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'sql-rest-format.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/sql-rest-format.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/sql-rest-format.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/sql-rest-format.html" rel="nofollow" target="_blank">../en/sql-rest-format.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="xpack-sql.html">SQL access</a></span>
»
<span class="breadcrumb-link"><a href="sql-rest.html">SQL REST API</a></span>
»
<span class="breadcrumb-node">Response Data Formats</span>
</div>
<div class="navheader">
<span class="prev">
<a href="sql-rest-overview.html">« Overview</a>
</span>
<span class="next">
<a href="sql-pagination.html">Paginating through a large response »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="sql-rest-format"></a>Response Data Formats<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/rest.asciidoc">edit</a>
</h2>
</div></div></div>
<p>While the textual format is nice for humans, computers prefer something
more structured.</p>
<p>Elasticsearch SQL can return the data in the following formats which can be set
either through the <code class="literal">format</code> property in the URL or by setting the <code class="literal">Accept</code> HTTP header:</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The URL parameter takes precedence over the <code class="literal">Accept</code> HTTP header.
If neither is specified then the response is returned in the same format as the request.</p>
</div>
</div>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
<col class="col_3">
</colgroup>
<tbody>
<tr>
<td align="center" valign="top"><p><span class="strong strong"><strong>format</strong></span></p></td>
<td align="center" valign="top"><p><span class="strong strong"><strong><code class="literal">Accept</code> HTTP header</strong></span></p></td>
<td align="center" valign="top"><p><span class="strong strong"><strong>Description</strong></span></p></td>
</tr>
<tr>
<td align="center" colspan="3" valign="top"><p><span class="strong strong"><strong>Human Readable</strong></span></p></td>
</tr>
<tr>
<td align="center" valign="top"><p><code class="literal">csv</code></p></td>
<td align="center" valign="top"><p><code class="literal">text/csv</code></p></td>
<td align="center" valign="top"><p><a href="https://en.wikipedia.org/wiki/Comma-separated_values" class="ulink" target="_top">Comma-separated values</a></p></td>
</tr>
<tr>
<td align="center" valign="top"><p><code class="literal">json</code></p></td>
<td align="center" valign="top"><p><code class="literal">application/json</code></p></td>
<td align="center" valign="top"><p><a href="https://www.json.org/" class="ulink" target="_top">JSON</a> (JavaScript Object Notation) human-readable format</p></td>
</tr>
<tr>
<td align="center" valign="top"><p><code class="literal">tsv</code></p></td>
<td align="center" valign="top"><p><code class="literal">text/tab-separated-values</code></p></td>
<td align="center" valign="top"><p><a href="https://en.wikipedia.org/wiki/Tab-separated_values" class="ulink" target="_top">Tab-separated values</a></p></td>
</tr>
<tr>
<td align="center" valign="top"><p><code class="literal">txt</code></p></td>
<td align="center" valign="top"><p><code class="literal">text/plain</code></p></td>
<td align="center" valign="top"><p>CLI-like representation</p></td>
</tr>
<tr>
<td align="center" valign="top"><p><code class="literal">yaml</code></p></td>
<td align="center" valign="top"><p><code class="literal">application/yaml</code></p></td>
<td align="center" valign="top"><p><a href="https://en.wikipedia.org/wiki/YAML" class="ulink" target="_top">YAML</a> (YAML Ain’t Markup Language) human-readable format</p></td>
</tr>
<tr>
<td align="center" colspan="3" valign="top"><p><span class="strong strong"><strong>Binary Formats</strong></span></p></td>
</tr>
<tr>
<td align="center" valign="top"><p><code class="literal">cbor</code></p></td>
<td align="center" valign="top"><p><code class="literal">application/cbor</code></p></td>
<td align="center" valign="top"><p><a href="http://cbor.io/" class="ulink" target="_top">Concise Binary Object Representation</a></p></td>
</tr>
<tr>
<td align="center" valign="top"><p><code class="literal">smile</code></p></td>
<td align="center" valign="top"><p><code class="literal">application/smile</code></p></td>
<td align="center" valign="top"><p><a href="https://en.wikipedia.org/wiki/Smile_(data_interchange_format)" class="ulink" target="_top">Smile</a> binary data format similar to CBOR</p></td>
</tr>
</tbody>
</table>
</div>
<p>Here are some examples for the human readable formats:</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_csv"></a>CSV<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/rest.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_sql?format=csv
{
    "query": "SELECT * FROM library ORDER BY page_count DESC",
    "fetch_size": 5
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/306.console"></div>
<p>Which returns:</p>
<div class="pre_wrapper lang-text">
<pre class="programlisting prettyprint lang-text">author,name,page_count,release_date
Peter F. Hamilton,Pandora's Star,768,2004-03-02T00:00:00.000Z
Vernor Vinge,A Fire Upon the Deep,613,1992-06-01T00:00:00.000Z
Frank Herbert,Dune,604,1965-06-01T00:00:00.000Z
Alastair Reynolds,Revelation Space,585,2000-03-15T00:00:00.000Z
James S.A. Corey,Leviathan Wakes,561,2011-06-02T00:00:00.000Z</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_json"></a>JSON<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/rest.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_sql?format=json
{
    "query": "SELECT * FROM library ORDER BY page_count DESC",
    "fetch_size": 5
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/307.console"></div>
<p>Which returns:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
    "columns": [
        {"name": "author",       "type": "text"},
        {"name": "name",         "type": "text"},
        {"name": "page_count",   "type": "short"},
        {"name": "release_date", "type": "datetime"}
    ],
    "rows": [
        ["Peter F. Hamilton",  "Pandora's Star",       768, "2004-03-02T00:00:00.000Z"],
        ["Vernor Vinge",       "A Fire Upon the Deep", 613, "1992-06-01T00:00:00.000Z"],
        ["Frank Herbert",      "Dune",                 604, "1965-06-01T00:00:00.000Z"],
        ["Alastair Reynolds",  "Revelation Space",     585, "2000-03-15T00:00:00.000Z"],
        ["James S.A. Corey",   "Leviathan Wakes",      561, "2011-06-02T00:00:00.000Z"]
    ],
    "cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWWWdrRlVfSS1TbDYtcW9lc1FJNmlYdw==:BAFmBmF1dGhvcgFmBG5hbWUBZgpwYWdlX2NvdW50AWYMcmVsZWFzZV9kYXRl+v///w8="
}</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_tsv"></a>TSV<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/rest.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_sql?format=tsv
{
    "query": "SELECT * FROM library ORDER BY page_count DESC",
    "fetch_size": 5
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/308.console"></div>
<p>Which returns:</p>
<div class="pre_wrapper lang-text">
<pre class="programlisting prettyprint lang-text">author	name	page_count	release_date
Peter F. Hamilton	Pandora's Star	768	2004-03-02T00:00:00.000Z
Vernor Vinge	A Fire Upon the Deep	613	1992-06-01T00:00:00.000Z
Frank Herbert	Dune	604	1965-06-01T00:00:00.000Z
Alastair Reynolds	Revelation Space	585	2000-03-15T00:00:00.000Z
James S.A. Corey	Leviathan Wakes	561	2011-06-02T00:00:00.000Z</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_txt"></a>TXT<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/rest.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_sql?format=txt
{
    "query": "SELECT * FROM library ORDER BY page_count DESC",
    "fetch_size": 5
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/309.console"></div>
<p>Which returns:</p>
<div class="pre_wrapper lang-text">
<pre class="programlisting prettyprint lang-text">     author      |        name        |  page_count   |      release_date
-----------------+--------------------+---------------+------------------------
Peter F. Hamilton|Pandora's Star      |768            |2004-03-02T00:00:00.000Z
Vernor Vinge     |A Fire Upon the Deep|613            |1992-06-01T00:00:00.000Z
Frank Herbert    |Dune                |604            |1965-06-01T00:00:00.000Z
Alastair Reynolds|Revelation Space    |585            |2000-03-15T00:00:00.000Z
James S.A. Corey |Leviathan Wakes     |561            |2011-06-02T00:00:00.000Z</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_yaml"></a>YAML<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/rest.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_sql?format=yaml
{
    "query": "SELECT * FROM library ORDER BY page_count DESC",
    "fetch_size": 5
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/310.console"></div>
<p>Which returns:</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">columns:
- name: "author"
  type: "text"
- name: "name"
  type: "text"
- name: "page_count"
  type: "short"
- name: "release_date"
  type: "datetime"
rows:
- - "Peter F. Hamilton"
  - "Pandora's Star"
  - 768
  - "2004-03-02T00:00:00.000Z"
- - "Vernor Vinge"
  - "A Fire Upon the Deep"
  - 613
  - "1992-06-01T00:00:00.000Z"
- - "Frank Herbert"
  - "Dune"
  - 604
  - "1965-06-01T00:00:00.000Z"
- - "Alastair Reynolds"
  - "Revelation Space"
  - 585
  - "2000-03-15T00:00:00.000Z"
- - "James S.A. Corey"
  - "Leviathan Wakes"
  - 561
  - "2011-06-02T00:00:00.000Z"
cursor: "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWWWdrRlVfSS1TbDYtcW9lc1FJNmlYdw==:BAFmBmF1dGhvcgFmBG5hbWUBZgpwYWdlX2NvdW50AWYMcmVsZWFzZV9kYXRl+v///w8="</pre>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="sql-rest-overview.html">« Overview</a>
</span>
<span class="next">
<a href="sql-pagination.html">Paginating through a large response »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>